package com.liaoban.app.ui.base;

import android.os.Bundle;

/**
 * 包含后退事件的Fragment
 * 使用这种BackHandledFragment 的Activity必须实现BackHandledInterface接口
 */
public abstract class BackHandledFragment extends BaseFragment {

    protected BaseActivity.BackHandledInterface mBackHandledInterface;

    public abstract boolean onBackPressed();

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        if (!(getActivity() instanceof BaseActivity.BackHandledInterface)) {
            throw new ClassCastException("Hosting Activity must implement BackHandledInterface");
        } else {
            this.mBackHandledInterface = (BaseActivity.BackHandledInterface) getActivity();
        }
    }

    @Override
    public void onStart() {
        super.onStart();
        mBackHandledInterface.setSelectedFragment(this);
    }
}

